<?php
/**
 * Created by PhpStorm.
 * User: 魏爷
 * Date: 2016/4/22
 * Time: 12:56
 */

namespace Admin\Controller;


class InfoManageController extends BaseController
{
    /**
     * 系统消息管理
     **/
    public function systemInfoManage(){
        $getSystemInfo=D('InfoManage')->getSystemInfo();
        $this->assign('_getSystemInfo',$getSystemInfo);
        $this->display('InfoManage/systemInfoManage');
    }
    /**
     * 系统消息详情
    **/
    public function systemInfo(){
        $system_id=I('system_id');
        $getSystemByIdInfo=D('InfoManage')->getSystemByIdInfo($system_id);
        $getAdminAllInfo=D('AdminLogin')->getAdminAllInfo();
        $this->assign('_getAdminAllInfo',$getAdminAllInfo);
        $this->assign('_getSystemByIdInfo',$getSystemByIdInfo);
        $this->display('InfoManage/systemInfo');
    }
    /**
     * 删除系统消息
    **/
    public function systemDel(){
        $system_id=I('system_id');
        $res=D('InfoManage')->systemDel($system_id);
        if($res==false){
            $this->error('删除失败',null,true);
        }else{
            $this->success('删除成功',null,true);
        }
    }
    /**
     * 消息添加
    **/
    public function systemAdd(){
        $a_id=getAdminId();
        $system_title=I('system_title');
        $system_intro=I('system_intro');
        $system_content=I('system_content');
        if(empty($a_id)||empty($system_title)||empty($system_intro)||empty($system_content)){
            $this->error('信息为空',null,true);
        }
        $res=D('InfoManage')->systemAdd($a_id,$system_title,$system_intro,$system_content);
        if($res==false){
            $this->error('提交失败',null,true);
        }else{
            $this->success('提交成功',null,true);
        }
    }
    /**
     * 借阅消息管理
    **/
    public function borrowManage(){
        $getAllTrueBorrowInfo=D('Borrow')->getAllTrueBorrowInfo();
        $getAllBookInfo=D('BookManage')->getAllBookInfo();
        $getAllUserInfo=D('User')->getAllUserInfo();
        $getAllReadType=D('ReadManage')->getAllReadType();
        $getAdminAllInfo=D('AdminLogin')->getAdminAllInfo();
        $this->assign('_getAdminAllInfo',$getAdminAllInfo);
        $this->assign('_getAllReadType',$getAllReadType);
        $this->assign('_getAllUserInfo',$getAllUserInfo);
        $this->assign('_getAllBookInfo',$getAllBookInfo);
        $this->assign('_getAllTrueBorrowInfo',$getAllTrueBorrowInfo);
        $this->display('InfoManage/borrowManage');
    }
    /**
     * 借阅订单管理
     **/
    public function borrowInfoManage(){
        $getNoIfBackIfo=D('Borrow')->getNoIfBackIfo();
        $getAllUserInfo=D('User')->getAllUserInfo();
        $getAllReadType=D('ReadManage')->getAllReadType();
        $getAllBookInfo=D('BookManage')->getAllBookInfo();
        $this->assign('_getAllReadType',$getAllReadType);
        $this->assign('_getNoIfBackIfo',$getNoIfBackIfo);
        $this->assign('_getAllUserInfo',$getAllUserInfo);
        $this->assign('_getAllBookInfo',$getAllBookInfo);
        $this->display('InfoManage/borrowInfoManage');
    }
    /**
     * 交易消息管理
    **/
    public function tradeManage(){
        $book_name=I('book_name');
        $buy_type=I('buy_type');
        $getBookByIdBuyInfo=D('BuyBook')->getBookByIdBuyInfo($book_name,$buy_type);
        $this->assign('_getBookByIdBuyInfo',$getBookByIdBuyInfo);
        $this->display('InfoManage/tradeManage');
    }
    /**
     * 交易订单管理
     **/
    public function tradeInfoManage(){
        $getBookBuyInfo=D('BuyBook')->getBookBuyInfo();
        $this->assign('_getBookBuyInfo',$getBookBuyInfo);
        $this->display('InfoManage/tradeInfoManage');
    }
    /**
     * 交易状态修改
    **/
    public function tradeInfoStatus(){
        $buybook_id=I('buybook_id');
        $res=D('BuyBook')->tradeInfoStatus($buybook_id);
        if($res==false){
            $this->error('确认失败',null,true);
        }else{
            $this->success('订单确认',null,true);
        }
    }
    /**
     * 交易状态完成
    **/
    public function tradeStatus(){
        $buybook_id=I('buybook_id');
        $res=D('BuyBook')->tradeStatus($buybook_id);
        if($res==false){
            $this->error('确认失败',null,true);
        }else{
            $this->success('订单完成',null,true);
        }
    }
    /**
     * 完成借阅
    **/
    public function goBookIfBack(){
        $a_id=getAdminId();
        $book_id=I('book_id');
        $borrow_id=I('borrow_id');
        $res=D('Borrow')->goBookIfBack($borrow_id,$a_id);
        if($res==false){
            $this->error('归还失败',null,true);
        }else{
            D('BookManage')->setBookBorrowNumber($book_id);
            $this->success('完成归还',null,true);
        }
    }
    /**
     * 驳回请求
    **/
    public function outBookIfBack(){
        $borrow_id=I('borrow_id');
        $res=D('Borrow')->outBookIfBack($borrow_id);
        if($res==false){
            $this->error('驳回失败',null,true);
        }else{
            $this->success('驳回成功',null,true);
        }
    }
}